//
//  SendDetailHeader.m
//  DriverUse
//
//  Created by angra on 16/11/2.
//  Copyright © 2016年 CJPC. All rights reserved.
//

#import "SendDetailHeader.h"
#import "HomeDetailModel.h"
@interface SendDetailHeader()
@property (nonatomic,weak)UILabel *startLabel;
@property (nonatomic,weak)UILabel *endLabel;
@property (nonatomic,weak)UILabel *dateLabel;
@property (nonatomic,weak)UILabel *timeLabel;
@property (nonatomic,weak)UILabel *shareType;
@property (nonatomic,weak)UILabel *countLabel;
@property (nonatomic,weak)UILabel *priceLabel;

@end


@implementation SendDetailHeader

-(instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"ffac2e"];;
        [self setInterface];
    }
    return self;
}
-(void)setInterface
{
    UIView *backView= [[UIView alloc]init];
    backView.backgroundColor = kWhiteColor;
    backView.layer.cornerRadius = 5;
    backView.clipsToBounds = YES;
    [self addSubview:backView];
    
    UILabel *startLabel = [self createLabelWithText:@"长沙" font:15 textColor:@"333333"];
    [backView addSubview:startLabel];
    _startLabel = startLabel;
    
    UIImageView *arrowImage = [[UIImageView alloc]init];
    arrowImage.image = [UIImage imageNamed:@"headerarrow"];
    [backView addSubview:arrowImage];
    
    UILabel *endLabel = [self createLabelWithText:@"湘潭" font:15 textColor:@"333333"];
    [backView addSubview:endLabel];
    _endLabel = endLabel;
    
    UILabel *dateLabel = [self createLabelWithText:@"2016年09月08日" font:14 textColor:@"666666"];
    [backView addSubview:dateLabel];
    _dateLabel = dateLabel;
    
    UILabel *timeLabel = [self createLabelWithText:@"17时30分" font:14 textColor:@"666666"];
    [backView addSubview:timeLabel];
    _timeLabel = timeLabel;
    
    UILabel *shareType = [self createLabelWithText:@"拼车方式：4人拼车 50/人" font:12 textColor:@"999999"];
    [backView addSubview:shareType];
    _shareType = shareType;
    
    UILabel *countLabel = [self createLabelWithText:@"拼车人数：2人" font:12 textColor:@"999999"];
    [backView addSubview:countLabel];
    _countLabel = countLabel;
    
    UILabel *priceLabel = [[UILabel alloc]init];
    priceLabel.font = [UIFont systemFontOfSize:font(kScaleNum(12))];
    priceLabel.textColor = kColoeString(@"ff3333");
    NSString *str = @"拼车费用：100元";
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    [attr addAttributes:@{
                         NSForegroundColorAttributeName:kColoeString(@"999999")} range:NSMakeRange(0, 5)];
    priceLabel.attributedText = attr;
    [backView addSubview:priceLabel];
    _priceLabel = priceLabel;
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(kScaleNum(10));
        make.right.equalTo(self).offset(kScaleNum(-10));
        make.top.equalTo(self);
        make.bottom.equalTo(self).offset(kScaleNum(-5));
    }];
    
    [startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView).offset(kScaleNum(15));
        make.top.equalTo(backView).offset(kScaleNum(10));
   
    }];
    [arrowImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startLabel.mas_right).offset(kScaleNum(5));
        make.centerY.equalTo(startLabel);
       
    }];
    [endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(arrowImage.mas_right).offset(kScaleNum(5));
        make.centerY.equalTo(startLabel);

    }];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startLabel);
        make.top.equalTo(startLabel.mas_bottom).offset(kScaleNum(7));
  
    }];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dateLabel.mas_right).offset(kScaleNum(115/2));
        make.centerY.equalTo(dateLabel);
    }];
    
    [shareType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startLabel);
        make.top.equalTo(dateLabel.mas_bottom).offset(kScaleNum(7));
    }];
    
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startLabel);
        make.top.equalTo(shareType.mas_bottom).offset(kScaleNum(7));
    }];
    
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startLabel);
        make.top.equalTo(countLabel.mas_bottom).offset(kScaleNum(7));
    }];

}
-(UILabel *)createLabelWithText:(NSString *)text font:(CGFloat)font textColor:(NSString *)hexColor
{
    UILabel *label = [[UILabel alloc]init];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font(kScaleNum(font))];
    label.textColor = kColoeString(hexColor);
    return label;
}
-(void)setModel:(HomeDetailModel *)model
{
    _model = model;
   
    _shareType.text = [NSString stringWithFormat:@"拼车方式：%@ %@/人", model.title.order_type, model.title.price];
    _countLabel.text = [NSString stringWithFormat:@"拼车人数：%@人",model.title.order_num];
    
    NSString *str = [NSString stringWithFormat:@"拼车费用：%@元",model.title.order_amt] ;
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    [attr addAttributes:@{
                          NSForegroundColorAttributeName:kColoeString(@"999999")} range:NSMakeRange(0, 5)];
    _priceLabel.attributedText = attr;
    NSArray *arr = [model.title.date_s componentsSeparatedByString:@" "];
    
    _timeLabel.text = [arr lastObject];
    _dateLabel.text = [arr firstObject];
    
    
}
-(void)setStart:(NSString *)start
{
    _start = start;
    self.startLabel.text = start;
}
-(void)setEnd:(NSString *)end
{
    _end = end;
    self.endLabel.text = end;
}
@end
